#!/bin/sh

# @license   http://www.gnu.org/licenses/gpl.html GPL Version 3
# @author    Ian Moore <imooreyahoo@gmail.com>
# @copyright Copyright (c) 2011 Ian Moore
#
# This file is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.

set -e

. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functions

# Only if enabled
if [ "$(omv_config_get "//services/cups/enable")" != "1" ]; then
    exit 0
fi

# Only samba if enabled
if [ "$(omv_config_get "//services/cups/enable_samba")" != "1" ]; then
    exit 0
fi


OMV_SAMBA_CONFIG=${OMV_SAMBA_CONFIG:-"/etc/samba/smb.conf"}

cat <<EOF >> ${OMV_SAMBA_CONFIG}

#======================= Printer Settings =======================
[global]
load printers = yes
printing = cups
printcap name = cups
disable spoolss = no
printcap cache time = 60
printer admin = @lpadmin

[printers]
comment = All Printers
path = /var/spool/samba
browseable = yes
guest ok = yes
writable = no
printable = yes

[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = no
guest ok = yes
read only = yes
write list = @lpadmin
oplocks = no
force create mode = 0664
force directory mode = 775

EOF
